<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!--
1. 使用v-model(双向数据绑定)自动收集数据
  text/textarea
  checkbox
  radio
  select
-->
<div id="demo">
    <form action="/xxx" @submit.prevent="handleSubmit">
      <span>用户名: </span>
      <input type="text" v-model="user.username"><br>
  
      <span>密码: </span> &nbsp;
      &nbsp;<input type="password" v-model="user.pwd"><br>
  
      <span>性别: </span>
      <input type="radio" id="female" value="female" v-model="user.sex">
      <label for="female">女</label>
      <input type="radio" id="male" value="male" v-model="user.sex">
      <label for="male">男</label><br>
  
      <span>爱好: </span>
      <input type="checkbox" id="basket" value="basket" v-model="user.likes">
      <label for="basket">篮球</label>
      <input type="checkbox" id="foot" value="foot" v-model="user.likes">
      <label for="foot">足球</label>
      <input type="checkbox" id="pingpang" value="pingpang" v-model="user.likes">
      <label for="pingpang">乒乓</label><br>
  
      <span>城市: </span>
      <select v-model="user.cityId">
        <option value="">未选择</option>
        <option :value="city.id" v-for="(city, index) in allCitys" :key="city.id">{{city.name}}</option>
      </select><br>
      <span>介绍: </span>
      <textarea rows="10" v-model="user.info"></textarea><br><br>
  
      <input type="submit" value="注册" @click.prevent='register'>
    </form>
  </div>
  
  <script type="text/javascript" src="../js/vue.js"></script>
  <script type="text/javascript">
    new Vue({
        el:'#demo',
        data(){
            return{
                user:{
                    username:'',
                    pwd:'',
                    sex:'male',//male男 female女
                   likes:['foot'], 
                    cityId:'2',
                    info:''
                },
                
                allCitys:[
                    {id:1,name:'BJ'},
                    {id:2,name:'SD'},
                    {id:3,name:'SH'},
                ],
              
                
            }
        },
        methods:{
            register(){
        
                alert(JSON.stringify(this.user));
            }
        }
        
    })
  </script>
</body>
</html>